<table data-options="fit:true" id="article_data"></table>

<script>
	$(function(){ 
		var datagrid; 
		datagrid=$('#article_data').datagrid({   
		    url:'../json/articleAction_findArticle',
		    loadMsg:'数据加载中...',
		    pagination:true, //分页控件
		    fitColumns:true,
		    rownumbers:true,
		    striped:true,
		    pageNumber:1,
		    sortOrder:'asc',
		    remoteSort:false,//定义是否通过远程服务器对数据排序。
		    sortName:'aid',
		    columns:[[
		    	{field:'aids',title:'',checkbox:true,width:100,align:'center'},   
		        {field:'aid',title:'杂志编号',width:100,align:'center'},   
		        {field:'aname',title:'杂志标题',width:200,align:'center'},   
		        {field:'aauthor',title:'杂志作者',width:100,align:'center'},
		        {field:'atime',title:'杂志收录时间',width:100,align:'center'},
		        {field:'atype',title:'杂志类型',width:100,align:'center'},
		        {field:'_operate',title:'操作',width:100,align:'center',
			        formatter: function(value,row,index){
						return "<a class='icon-file icon-padding' href=\"javascript:showTuanDetailes\">详细</a>";	
					}
		        }
		    ]],
		    toolbar: [{
		    	text:'添加',
				iconCls: 'icon-add',
				handler: function(){
					$("#article_data_add").dialog("open");
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
					//获取选中的行
					var rows=datagrid.datagrid("getChecked");
					if(rows.length==0){
						$.messager.alert('错误提示','请选择您要删除的文章...','error');
					}else{
						//获取到行中的id
						var aid="";
						//如果有多个
						if(rows.length>1){
							for(var i=0;i<rows.length-1;i++){
								aid+=rows[i].aid+",";
							}
							aid+=rows[i].aid;
						}else{
							aid=rows[0].aid;
						}
						$.post("../json/articleAction_delArticle",{'article.aid':aid},function(data){
							if(data.result>0){
								$.messager.show({
									title:'成功提示',
									msg:'删除文章成功...',
									timeout:3000,
									showType:'slide'
								});
								datagrid.datagrid("reload");
							}else{
								$.messager.alert('错误提示','文章删除失败,请稍后重试...','error');
							}
						});
					}
				}
			},'-',{
				text:'修改',
				iconCls: 'icon-edit',
				handler: function(){
					$("#article_data_add").dialog("open");
                }
           }]
		});
	});
</script>

<div id="article_data_add" class="easyui-dialog" title="添加杂志" style="width:800px;height:600px"
	data-options="iconCls:'icon-add',resizeble:true,modal:true,closed:true">
	<br /><br />
	<form action="" style="float:left;padding-left:20px" id="myArticle" name="myArticle" method="post">
		<input type="hidden" value="addArticle" name="op">
		<label>杂志题目：</label><input type="text" name="aname" id="article_aname">
		<label>杂志类型：</label>
			<select name="atype" id="article_atype">
				<option>请选择类型：</option>
				<option value="婚恋">婚恋</option>
				<option value="亲子">亲子</option>
				<option value="职场">职场</option>
				<option value="健康">健康</option>
				<option value="科普">科普</option>
			</select>
		
		<label>杂志作者：</label><input type="text" name="aauthor" id="article_aauthor">
		<label>杂志图片：</label><input type="file" name="file" id="article_aaddr" onchange="previewMultipleImage(this,'show_pic')">
		<div style="width=120px;height=80px;boder:1px solid #ccc;" id="show_pic">
				
		</div>
		
		<label>杂志内容:</label>
		<div>
			<script type="text/plain" id="editor" style="width:750px;height:200px"></script>
		</div>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addArticle()">添加</a>			
	</form>
</div>

<script>
	var ue=UE.getEditor('editor');
	
		
	function addArticle(){
		//获取值
		var aname=$("#article_aname").val();
		var atype=$("#article_atype").val();
		var aauthor=$("#article_aauthor").val();
		var aaddr=$("#article_aaddr").val();  //图片
		var acontent=ue.getContent();
		
		var date = new Date();
		var h = date.getHours();   //小时
		var m = date.getMinutes().toString();   //分
		var time=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+h+":"+m;
		
		//发送请求
		$.ajaxFileUpload({
			url:"../upload/articleAction_addArticle",
			fileElementId:["article_aaddr"],
			secureuri:false,
			dataType:'json', 
			data:{
				'article.aname':aname,
				'article.atype':atype,
				'article.aauthor':aauthor,
				'article.aaddr':aaddr,
				'article.acontent':acontent,
				'article.atime':time
			},
			success:function(data){
				if(data.result==1 ){
					$.messager.show({
						title:'成功提示',
						msg:'文章添加成功...',
						timeout:3000,
						showType:'slide'
					});
					ue.setContent("");
					$("#show_pic").html("");
					$("#myArticle")[0].reset();
					$('#article_data_add').dialog("close");
					$('#article_data').datagrid("reload");
				}else{
					$.messager.alert('错误提示','文章添加失败,请稍后重试...','error');
				}
			}
		});
	}
</script>

